import java.sql.*;
import javax.swing.JOptionPane;

public class DataSet {
		ResultSet results;
		ResultSetMetaData rsmd;
		int columnCount;
		String[] columnNames;

  public DataSet(ResultSet results){
    try {
      this.results = results;
      rsmd = results.getMetaData();
      columnCount = rsmd.getColumnCount();
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
    }
  }

  	public boolean hasMoreElements() {
  		try{
  			return results.next();
  		}	
  		catch (SQLException ex){
  			JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
  			return false;
  		}
  }

  public String[] getMetaData() {
    String[] s;
    s = new String[columnCount+1];
    try{
      results.next();
      for (int i=1; i<=columnCount; i++){
        s[i] = results.getString(i);
      }
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
    }
    return s;
  }

  public String[] nextElement() {
    String[] line;
    line = new String[columnCount+1];
    try{
      for (int i = 1; i <= columnCount; i++){
        line[i] = results.getString(i);
      }
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
    }
    return line;
  }

  public String getColumnValue(String columnName) {
    try{
      return results.getString(columnName);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return "";
    }
  }

  	/**
  	 * @return
  	 * @uml.property  name="columnCount"
  	 */
  	public int getColumnCount(){
  		return columnCount;
  	}

  public String getColumnName(int i) {
    try{
      return rsmd.getColumnName(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return "";
    }
  }

  public String getColumnLabel(int i) throws SQLException {
    try{
      return rsmd.getColumnLabel(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return "";
    }
  }

  public int getColumnDisplaySize(int i) throws SQLException {
    try{
      return rsmd.getColumnDisplaySize(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return 0;
    }
  }

  public int getColumnType(int i) throws SQLException{
    try{
      return rsmd.getColumnType(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return 0;
    }
  }

  public String getColumnTypeName(int i) throws SQLException{
    try{
      return rsmd.getColumnTypeName(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return "";
    }
  }

  public String getCatalogName(int i) throws SQLException{
    try{
      return rsmd.getCatalogName(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return "";
    }
  }

  public boolean isAutoIncrement(int i) throws SQLException{
    try{
      return rsmd.isAutoIncrement(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return false;
    }
  }

  public String getSchemaName(int i) throws SQLException{
    try{
      return rsmd.getSchemaName(i);
    }
    catch (SQLException ex){
      JOptionPane.showMessageDialog(null, ex.getMessage(), "Exception SQL", JOptionPane.ERROR_MESSAGE);
      return "";
    }
  }
  
}

